﻿; $(function () {
    $("#toolbar").ligerToolBar({
        items: [{
            text: '添加',
            icon: '',
            id: 'btnSave',
            click: function (parameters) {
                location.href = "/Product/Product";
            }
        },
            {
                text: '编辑',
                icon: '',
                id: 'btnEdit',
                click: function (parameters) {
                    var rows = manager.getSelectedRows();
                    if (rows && rows.length == 1) {
                        var row = manager.getSelectedRow();
                        if (row && row.PartitionId != "") {
                            //if (row.IsChecked == 1) {
                            //} else {
                            location.href = "/Product/Product?Id=" + row.Id;
                            // }
                        } else {
                            $.ligerDialog.warn('请选择单个产品');
                        }
                    } else {
                        $.ligerDialog.warn('请选择单个产品');
                    }
                }
            },
            {
                text: '删除',
                icon: '',
                id: 'btnDelete',
                click: function (parameters) {

                    var rows = manager.getSelectedRows();
                    if (rows && rows.length > 0) {
                        var ids = new Array();
                        $.each(rows, function () {
                            ids.push(this.Id);
                        });
                        $.ajax({
                            url: '/Product/DeleteProducts',
                            dataType: 'json',
                            type: 'post',
                            data: { ids: ids.join(",") },
                            traditional: true,
                            success: function (callback) {
                                if (callback) {
                                    $.ligerDialog.alert('删除成功', function (yes) {
                                        manager.loadData();
                                    });
                                }
                                else {
                                    $.ligerDialog.error('删除失败');
                                }
                            },
                            error: function (ex) {
                                $.ligerDialog.error('删除失败');
                            }
                        });
                    } else {

                    }


                }
            }]
    });


    var manager = $("#grid").ligerGrid({
        columns: [
            //{
            //    display: '序号',
            //    align: 'center',
            //    width: 50,
            //    minWidth: 50,
            //    render: function (item, i) {
            //        return (i + 1).toString();
            //    }
            //},
            {
                display: '产品名称',
                align: 'left',
                width: 200,
                minWidth: 100,
                name: 'ProductName'
            },
            { display: '厂家(产地)', name: 'Manufacturers', isSort: false, width: 250, align: 'left' },
             { display: '型号', name: 'Model', isSort: false, width: 50, align: 'left' },
            {
                display: '用途', name: 'Purpose', isSort: false, width: 80, align: 'left'
            },
            {
                display: '价格', name: 'Price', isSort: false, width: 80, align: 'center', render: function (item, i, value) {
                    return item.Price + " " + item.PriceUnit;
                }
            }
        //,
        //    {
        //        display: '审核状态', name: 'IsChecked', isSort: false, width: 80,hide:true, align: 'center', render: function (item, i, value) {
        //            var t = item.IsChecked;
        //            switch (t) {
        //                case 1:
        //                    return "已通过";
        //                case 2:
        //                    return "未通过";
        //                default:
        //                    return "待审核";
        //            }

        //        }
        //    }
        ],
        width: '99.85%',
        height:
            '100%',
        heightDiff:
            -20,
        pageSizeOptions:
            [5, 10, 15, 20],
        pageSize:15,
        //data: TreeDeptData,
        alternatingRow:
            false,
        url:
            "/Product/Products",
        headerRowHeight:
            26,
        checkbox: true,
        autoCheckChildren: false,
        dataAction: "server",
        rowAttrRender:
            function (item, index) {
                return "";
            }
    });
   
});